import numpy as np
import math
import matplotlib.pyplot as plt
    
def InterpolationSin(TP,step=1,sd = [-math.pi/2,math.pi/2]):
    # sd表示sin函数取值段，范围在-1.57到1.57之间，中间值为0
        if sd[0]<-math.pi/2:sd[0] = -math.pi/2
        if sd[1]>math.pi/2:sd[1] = math.pi/2
        if step<=2:
            return TP
        else:
            rlist = np.zeros((step,len(TP[0])))
            rlist1 = np.zeros((step, len(TP[0])))
            for i in range(len(TP[0])):
                aline = np.linspace(TP[0][i],TP[1][i],step)
                jline = np.linspace(sd[0],sd[1],step)
                for j in range(len(aline)):
                    rlist[j][i] = aline[j]
                    # sq = (math.sin(jline[j])+1)/2
                    sq = (math.sin(jline[j])-math.sin(sd[0]))/(math.sin(sd[1])-math.sin(sd[0]))
                    rlist1[j][i] = round((TP[1][i]-TP[0][i])*sq+TP[0][i],2)
            return rlist1
        
if __name__ == "__main__":
    step = 10
    r = InterpolationSin([[0.0,0.0,0.0],[10.0,10.0,10.0]],step=step,sd=[-1,2])
    
    
    xlist = np.arange(0,step,1)
    ylist = r[:,1]
    # print(xlist)
    # print(ylist)
    
    
    plt.plot(xlist, ylist,"ob:")
    plt.show()
    